package com.fyzk.random;

import com.fyzk.activity.lottery.shuzicai.BallInfo;
import com.fyzk.betcode.AppLotteryCodeListManager;
import com.fyzk.betcode.BetLotteryInfo;
import com.fyzk.betcode.CodeFactory;
import com.fyzk.utils.LotteryIDUtils;
import com.fyzk.utils.RandomUtil;

import java.util.List;

/**
 * Created by miao on 2016/12/21.
 */
public class KLSFRandom extends RandomBase {
    int maxNum = 20;
    @Override
    public int[] randomDanHang(int count) {
        int[] arr = RandomUtil.randomNoRepeat(count, 0, maxNum);
        return arr;
    }

    public int[] randomDanHong(int count) {
        int[] arr = RandomUtil.randomNoRepeat(count, 0, 2);
        return arr;
    }

    public int[] randomShu1(int count) {
        int[] arr = RandomUtil.randomNoRepeat(count, 0, 18);
        return arr;
    }

    @Override
    public void randomYiZhu(BetLotteryInfo infor) {
        int wcodeID = infor.wcodeID;
        int popupID = infor.popupID;
        int zhuShu = 1;

        List<List<BallInfo>> arr_infos = infor.arr_infos;
        arr_infos = initList(arr_infos);

        maxNum = 20;
        switch (wcodeID) {
            case LotteryIDUtils.KLSF_LOTTERY_XUANYI_SHU_DAN_ID_INT:
            case LotteryIDUtils.KLSF_LOTTERY_XUANYI_SHU_FU_ID_INT:
                popupID = 0;
                maxNum = 18;
                wcodeID = LotteryIDUtils.KLSF_LOTTERY_XUANYI_SHU_DAN_ID_INT;
                randomRen(arr_infos, 1);
                break;
            case LotteryIDUtils.KLSF_LOTTERY_XUANYI_HONG_DAN_ID_INT:
                popupID = 1;
                maxNum = 2;
                wcodeID = LotteryIDUtils.KLSF_LOTTERY_XUANYI_HONG_DAN_ID_INT;
                randomRen(arr_infos, 1);
                break;
            case LotteryIDUtils.KLSF_LOTTERY_RENER_DAN_ID_INT:
            case LotteryIDUtils.KLSF_LOTTERY_RENER_FU_ID_INT:
            case LotteryIDUtils.KLSF_LOTTERY_RENER_TOWED_ID_INT:
                popupID = 2;
                wcodeID = LotteryIDUtils.KLSF_LOTTERY_RENER_DAN_ID_INT;
                randomRen(arr_infos, 2);
                break;
            case LotteryIDUtils.KLSF_LOTTERY_RENSAN_DAN_ID_INT:
            case LotteryIDUtils.KLSF_LOTTERY_RENSAN_FU_ID_INT:
            case LotteryIDUtils.KLSF_LOTTERY_RENSAN_TOWED_ID_INT:
                popupID = 3;
                wcodeID = LotteryIDUtils.KLSF_LOTTERY_RENSAN_DAN_ID_INT;
                randomRen(arr_infos, 3);
                break;
            case LotteryIDUtils.KLSF_LOTTERY_RENSI_DAN_ID_INT:
            case LotteryIDUtils.KLSF_LOTTERY_RENSI_FU_ID_INT:
            case LotteryIDUtils.KLSF_LOTTERY_RENSI_TOWED_ID_INT:
                popupID = 4;
                wcodeID = LotteryIDUtils.KLSF_LOTTERY_RENSI_DAN_ID_INT;
                randomRen(arr_infos, 4);
                break;
            case LotteryIDUtils.KLSF_LOTTERY_RENWU_DAN_ID_INT:
            case LotteryIDUtils.KLSF_LOTTERY_RENWU_FU_ID_INT:
            case LotteryIDUtils.KLSF_LOTTERY_RENWU_TOWED_ID_INT:
                popupID = 5;
                wcodeID = LotteryIDUtils.KLSF_LOTTERY_RENWU_DAN_ID_INT;
                randomRen(arr_infos, 5);
                break;
            case LotteryIDUtils.KLSF_LOTTERY_XUANER_LIANZU_DAN_ID_INT:
            case LotteryIDUtils.KLSF_LOTTERY_XUANER_LIANZU_FU_ID_INT:
            case LotteryIDUtils.KLSF_LOTTERY_XUANER_LIANZU_TOWED_ID_INT:
                popupID = 7;
                wcodeID = LotteryIDUtils.KLSF_LOTTERY_XUANER_LIANZU_DAN_ID_INT;
                randomRen(arr_infos, 2);
                break;
            case LotteryIDUtils.KLSF_LOTTERY_XUANER_LIANZHI_DAN_ID_INT:
            case LotteryIDUtils.KLSF_LOTTERY_XUANER_LIANZHI_FU_ID_INT:
                popupID = 6;
                wcodeID = LotteryIDUtils.KLSF_LOTTERY_XUANER_LIANZHI_DAN_ID_INT;
                randomTwoStraight(arr_infos);
                break;
            // 广东快乐十分
            case LotteryIDUtils.GDKLSF_LOTTERY_XUANYI_SHU_DAN_ID_INT:
            case LotteryIDUtils.GDKLSF_LOTTERY_XUANYI_SHU_FU_ID_INT:
                popupID = 0;
                maxNum = 18;
                wcodeID = LotteryIDUtils.GDKLSF_LOTTERY_XUANYI_SHU_DAN_ID_INT;
                randomRen(arr_infos, 1);
                break;
            case LotteryIDUtils.GDKLSF_LOTTERY_XUANYI_HONG_DAN_ID_INT:
                popupID = 1;
                maxNum = 2;
                wcodeID = LotteryIDUtils.GDKLSF_LOTTERY_XUANYI_HONG_DAN_ID_INT;
                randomRen(arr_infos, 1);
                break;
            case LotteryIDUtils.GDKLSF_LOTTERY_RENER_DAN_ID_INT:
            case LotteryIDUtils.GDKLSF_LOTTERY_RENER_FU_ID_INT:
            case LotteryIDUtils.GDKLSF_LOTTERY_RENER_TOWED_ID_INT:
                popupID = 2;
                wcodeID = LotteryIDUtils.GDKLSF_LOTTERY_RENER_DAN_ID_INT;
                randomRen(arr_infos, 2);
                break;
            case LotteryIDUtils.GDKLSF_LOTTERY_RENSAN_DAN_ID_INT:
            case LotteryIDUtils.GDKLSF_LOTTERY_RENSAN_FU_ID_INT:
            case LotteryIDUtils.GDKLSF_LOTTERY_RENSAN_TOWED_ID_INT:
                popupID = 3;
                wcodeID = LotteryIDUtils.GDKLSF_LOTTERY_RENSAN_DAN_ID_INT;
                randomRen(arr_infos, 3);
                break;
            case LotteryIDUtils.GDKLSF_LOTTERY_RENSI_DAN_ID_INT:
            case LotteryIDUtils.GDKLSF_LOTTERY_RENSI_FU_ID_INT:
            case LotteryIDUtils.GDKLSF_LOTTERY_RENSI_TOWED_ID_INT:
                popupID = 4;
                wcodeID = LotteryIDUtils.GDKLSF_LOTTERY_RENSI_DAN_ID_INT;
                randomRen(arr_infos, 4);
                break;
            case LotteryIDUtils.GDKLSF_LOTTERY_RENWU_DAN_ID_INT:
            case LotteryIDUtils.GDKLSF_LOTTERY_RENWU_FU_ID_INT:
            case LotteryIDUtils.GDKLSF_LOTTERY_RENWU_TOWED_ID_INT:
                popupID = 5;
                wcodeID = LotteryIDUtils.GDKLSF_LOTTERY_RENWU_DAN_ID_INT;
                randomRen(arr_infos, 5);
                break;
            case LotteryIDUtils.GDKLSF_LOTTERY_XUANER_LIANZU_DAN_ID_INT:
            case LotteryIDUtils.GDKLSF_LOTTERY_XUANER_LIANZU_FU_ID_INT:
            case LotteryIDUtils.GDKLSF_LOTTERY_XUANER_LIANZU_TOWED_ID_INT:
                popupID = 7;
                wcodeID = LotteryIDUtils.GDKLSF_LOTTERY_XUANER_LIANZU_DAN_ID_INT;
                randomRen(arr_infos, 2);
                break;
            case LotteryIDUtils.GDKLSF_LOTTERY_XUANER_LIANZHI_DAN_ID_INT:
            case LotteryIDUtils.GDKLSF_LOTTERY_XUANER_LIANZHI_FU_ID_INT:
                popupID = 6;
                wcodeID = LotteryIDUtils.GDKLSF_LOTTERY_XUANER_LIANZHI_DAN_ID_INT;
                randomTwoStraight(arr_infos);
                break;
            default:
                break;
        }

        String Zhuma = CodeFactory.getCode(wcodeID).betCode(arr_infos);
        String showZhuMa = CodeFactory.getCode(wcodeID).formatHtmlCode2(Zhuma);
        AppLotteryCodeListManager.getInstance().AddLotteryInfo(wcodeID,
                Zhuma, showZhuMa, zhuShu, arr_infos, popupID);
    }

    /**
     * 机选号（一排球）
     * @param num
     */
    private void randomRen(List<List<BallInfo>> arr_infos, int num){
        int arr[] = randomDanHang(num);
        for (int i = 0; i < arr.length; i++) {
            arr_infos.get(0).get(arr[i]).setSelected(true);
        }
    }

    /**
     * 选二连直机选
     */
    private void randomTwoStraight(List<List<BallInfo>> arr_infos){
        int arr[] = randomDanHang(2);
        int first = arr[0];
        int two = arr[1];
        arr_infos.get(0).get(first).setSelected(true);
        arr_infos.get(1).get(two).setSelected(true);
    }
}
